package com.ruoyi.web.controller.saas;

import com.bonuo.saas.domain.WorkOrder;
import com.bonuo.saas.service.WorkOrderService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "工单管理")
@RestController
@RequestMapping("/saas/workOrder")
public class WorkOrderController extends BaseController {

    @Autowired
    private WorkOrderService workOrderService;

    @ApiOperation(value = "查询工单列表",httpMethod = "GET")
    @GetMapping("/list")
    public AjaxResult list(WorkOrder workOrder, Integer pageNum, Integer pageSize){
        if(pageNum != null && pageSize != null){
            PageHelper.startPage(pageNum,pageSize);
        }
        List<WorkOrder> list = workOrderService.selectWorkOrderList(workOrder);
        return success(new PageInfo<>(list));
    }

    @ApiOperation(value = "添加工单",httpMethod = "POST")
    @PostMapping("/add")
    public AjaxResult add(@RequestBody WorkOrder workOrder){
        //返回工单自增ID
        int i = workOrderService.insertWorkOrder(workOrder);
        return i>0?success(workOrder.getId()):error();
    }

    @ApiOperation(value = "修改工单",httpMethod = "PUT")
    @PutMapping("/update")
    public AjaxResult update(@RequestBody WorkOrder workOrder){
        return toAjax(workOrderService.updateWorkOrder(workOrder));
    }

    @ApiOperation(value = "删除工单",httpMethod = "DELETE")
    @DeleteMapping("/delete/{id}")
    public AjaxResult delete(@PathVariable Integer id){
        return toAjax(workOrderService.deleteWorkOrderById(id));
    }

}
